﻿using Inventorycount.API.Write.Application.Command;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace Inventorycount.API.Write.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TransferController : ControllerBase
    {

        private readonly IMediator _mediator;
        private readonly ILogger<TransferController> logger;

        public TransferController(IMediator mediator, ILogger<TransferController> logger)
        {
            _mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 添加调拨
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddTransfer([FromBody] AddTransferCommand command)
        {
            logger.LogInformation("添加调拨成功");
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 删除调拨
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> DeleteTransfer([FromQuery] int Id)
        {
            logger.LogInformation("删除调拨成功");
            DeleteTransferCommand command = new DeleteTransferCommand()
            {
                Id = Id
            };
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 修改调拨
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> UpdateTransfer([FromBody] UpdateTransferCommand command)
        {
            logger.LogInformation("修改调拨成功");
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 入库审批
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpdateinboundStatus([FromQuery] UpdateinboundStatusCommand command)
        {
            logger.LogInformation("入库审批成功");
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 出库审批
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpdateonboundStatus([FromQuery] UpdateonboundStatusCommand command)
        {
            logger.LogInformation("出库审批成功");
            var result = await _mediator.Send(command);
            return Ok(result);
        }
    }
}
